//
//  WQStatusModel.swift
//  WeiBo
//
//  Created by Xmen on 16/9/25.
//  Copyright © 2016年 111. All rights reserved.
//

import UIKit

class WQStatusModel: NSObject {

    //  微博模型对象
    var status: WQStatus?
    //  提供会员等级图片
    var mbrankImage: UIImage?
    //  转发数
    var retweetCountContent: String?
    //  评论数
    var commentCountContent: String?
    //  赞
    var unlikeCountContent: String?
    //  转发微博内容
    var retweetContent: String?
    
    init(status: WQStatus) {
        super.init()
        self.status = status
        
        
        
        handleMBrankImage(mbrank: status.user?.mbrank ?? 0)
        
        retweetCountContent = handleCountContent(count: status.reposts_count, defaultTitle: "转发")
        commentCountContent = handleCountContent(count: status.comments_count, defaultTitle: "评论")
        unlikeCountContent = handleCountContent(count: status.attitudes_count, defaultTitle: "赞")
        
        
        handleRetweetContent(status: status)
    }
    
    //  处理转发微博内容显示
    private func handleRetweetContent(status: WQStatus) {
        
        if status.retweeted_status != nil {
            //  获取转发微博的用户名
            let name = status.retweeted_status?.user?.screen_name
            
            //  获取转发微博的内容
            let text = status.retweeted_status?.text
            
            if name != nil && text != nil {
                //  转发微博内容拼接
                retweetContent = "@\(name!): \(text!)"
                
                
            }
            
        }
        
        
    }
    
    
    //  处理转发,评论,赞数据显示
    private func handleCountContent(count: Int, defaultTitle: String) -> String {
        
        if count > 0 {
            return "\(count)"
        } else {
            return defaultTitle
        }
        
        
    }
    
    
    //  处理会员等级逻辑
    private func handleMBrankImage(mbrank: Int) {
        
        //  判断数据是否在1-6之间
        
        if mbrank >= 1 && mbrank <= 6 {
            
            mbrankImage = UIImage(named: "common_icon_membership_level\(mbrank)")
            
        }
        
    }

}
